#库导入#
import sensor, image, time,  network, usocket, sys
from pyb import UART, LED
import random
#库导入#

#找出返回色块列表中最大色块#
def findMaxBlob(blobs):
    MaxSize = 0
    for blob in blobs:
            if blob[2]*blob[3] >= MaxSize:
                MaxSize = blob[2]*blob[3]
                MaxBlob = blob
    return MaxBlob2
#找出返回色块列表中最大色块#

#数据打包#
def outuart(x,y):
    global uart
    #发送数据
    uart.write('@')
    uart.write(str(x))
    uart.write(',')
    uart.write(str(y))
    uart.write(',')
    uart.write('\r')
    uart.write('\n')
#    output_str="@%d,%d\r\n" %(x,y) #方式1，帧头帧尾自定义字符
#    uart.write(output_str)
#    data=bytearray([0x40,0x01,0x02,0x20,0x05,x,0x0d])
#    uart.write(data)
#    data=bytearray([0x40,0x01,0x02,0x20,0x06,y,0x0d])
#    uart.write(data)
#数据打包#

#UART初始化#
uart = UART(3,4800)
uart.init(4800, bits=8, parity=None, stop=1)
#UART初始化#

#补光程序
LED(1).on()
LED(2).on()
LED(3).on()

#摄像头初始化#
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
#sensor.skip_frames(time = 2000)
#摄像头初始化#

#时钟初始化#
clock = time.clock()
#时钟初始化#

#屏幕初始化#
#screen_baudrate SPI频率 默认78 单位Mhz
#pressure 压力阈值 默认1000
#screen.init()
#屏幕初始化#


while(True):
    clock.tick()
    img = sensor.snapshot()
    #time.sleep_ms(20)
    num_1 = random.randint(0,10000)
    num_2 = random.randint(0,10000)
    outuart(num_1,num_2)
    #帧速#
    #print(clock.fps())
    #帧速#
